#include<bits/stdc++.h>
using namespace std;
const int N=(1<<20)+99,inf=1e6;
multiset<int> lp,rp,msl[N],msr[N];
multiset<int>::iterator it;
#define ln node<<1
#define rn node<<1|1
#define mid (l+r>>1)
struct tree{
	int ans;
	int lmn,rmx;
}tr[N<<1];
int id[N];
void pushup(int node){
	tr[node].ans=min(min(tr[ln].ans,tr[rn].ans),tr[rn].lmn-tr[ln].rmx);
	tr[node].lmn=min(tr[ln].lmn,tr[rn].lmn);
	tr[node].rmx=max(tr[ln].rmx,tr[rn].rmx);
	return;
}
void build(int node,int l,int r){
	tr[node]=(tree){2*inf,2*inf,-2*inf};
	if(l==r){ id[l]=node; return; }
	build(ln,l,mid); build(rn,mid+1,r);
	return;
}
void upd(int tar){
	int node=id[tar];
	if(msl[tar].empty()) tr[node].lmn=2*inf;
	else tr[node].lmn=*msl[tar].begin();
	if(msr[tar].empty()) tr[node].rmx=-2*inf;
	else{ it=msr[tar].end(); it--; tr[node].rmx=*it; }
	tr[node].ans=tr[node].lmn-tr[node].rmx;
	node>>=1;
	while(node){
		pushup(node);
		node>>=1;
	}
	return;
}
char ch;
int l,r,ansl,ansr;
void solve(){
	cin>>ch>>l>>r;
	if(ch=='A'){
		lp.insert(l); rp.insert(r);
		msl[l].insert(r); msr[r].insert(l);
	}
	else{
		lp.erase(lp.find(l)); rp.erase(rp.find(r));
		msl[l].erase(msl[l].find(r)); msr[r].erase(msr[r].find(l));
	}
	upd(l); upd(r);
	it=lp.end(); it--; ansl=*it;
	it=rp.begin(); ansr=*it;
	if(ansl>ansr) cout<<tr[1].ans<<'\n';
	else{
		it=msr[ansr].end(); it--;
		cout<<*msl[ansl].begin()-(*it)<<'\n';
	}
	return;
}
int main(){
	freopen("stone.in","r",stdin);
	freopen("stone.out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	build(1,1,inf);
	int T; cin>>T;
	while(T--) solve();
	return 0;
}